package read;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class CardDemo {
    public static final String[] SUITS = {"♦","♣","♥","♠"};
    public static List<Crad> buyDeck() {
        List<Crad> cradlist = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for(int j = 1; j < 14;j++) {
                String sutis = SUITS[i];
                Crad crad = new Crad(sutis,j);
                cradlist.add(crad);
            }
        }
        return cradlist;
    }

    public static void shuffle(List<Crad> deck) {
        Random random = new Random();
        for(int i = deck.size() - 1;i > 0;i--) {
            int index = random.nextInt(i);
            swap(deck,i,index);
        }
    }

    private static void swap(List<Crad> deck,int i,int j) {
        Crad tmp = deck.get(i);
        deck.set(i,deck.get(j));
        deck.set(j,tmp);
    }

}
